package com.atguigu.gulimall.product.controller;


import com.atguigu.gulimall.product.entity.PmsBrand;
import com.atguigu.gulimall.product.service.IPmsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 品牌 前端控制器
 * </p>
 *
 * @author szh
 * @since 2020-12-01
 */
@RestController
@RequestMapping("product/brand")
public class PmsBrandController {
	@Autowired
	private IPmsBrandService brandService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		PageUtils page = brandService.queryPage(params);

		return R.ok().put("page", page);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{brandId}")
	public R info(@PathVariable("brandId") Long brandId){
		PmsBrand brand = brandService.getById(brandId);

		return R.ok().put("brand", brand);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody PmsBrand brand){
		brandService.save(brand);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody PmsBrand brand){
		brandService.updateDetail(brand);

		return R.ok();
	}
	/**
	 * 修改
	 */
	@RequestMapping("/update/status")
	public R updateStatus(@RequestBody PmsBrand brand){
		boolean b = brandService.updateById(brand);
		if(b){
			return R.ok();
		}else {
			return R.error();
		}

	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

		return R.ok();
	}

	@GetMapping("/selectTest")
	public R selectTest(){
		PmsBrand pmsBrand = brandService.selectTest();
		return R.ok().put("data",pmsBrand);
	}

}
